package com.mbd.rover;

import com.mbd.field.Field;

/**
 * The rover
 * 
 * @author milena.bd@gmail.com
 */
public class Rover {

	/** INITIAL_STATE */
	private static final char[][] INITIAL_STATE = new char[][] {
			{ ' ', '.', ' ' }, { '.', '.', '.' }, { ' ', ' ', ' ' } };

	private char[][] state = null;

	@SuppressWarnings("unused")
	private Field field = null;

	/**
	 * Конструктор
	 * 
	 * @param fieldToDiscover
	 */
	public Rover(Field fieldToDiscover) {
		super();
		setState(INITIAL_STATE);
		setField(fieldToDiscover);
	}

	/**
	 * JAVADOC
	 */
	public void rotateClockwiseBy90Degrees() {

		int rows = getState().length;
		int cols = getState()[0].length;

		char[][] rotated = new char[cols][rows];

		for (int row = 0; row < rows; row++) {
			for (int col = 0; col < cols; col++) {
				rotated[col][rows - 1 - row] = getState()[row][col];
			}
		}

		setState(rotated);
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		for (char[] element : this.state) {
			for (char element2 : element) {
				builder.append(element2);
			}
			builder.append("\n");
		}
		return builder.toString();
	}

	private char[][] getState() {
		return this.state;
	}

	private void setState(char[][] state) {
		this.state = state;
	}

	private void setField(Field field) {
		this.field = field;
	}

}
